import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({
  easing: 'ease', // 动画方式
  speed: 500, // 递增进度条的速度
  showSpinner: true, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3 // 初始化时的最小百分比
})

let title = '';

Vue.use(VueRouter);
import util from './util';
import routerContent from './router';


let routerMain = [
  {
    path: '',
    redirect: '/groupList',
  },
  {
    path: '*',
    redirect: '/'
  }]

const router = new VueRouter({
  mode: 'history',
  scrollBehavior:(to,from,position)=>{
    if(position){
      return position
    }else{
      return {x:0,y:0}
    }
  },
  routes: [
    ...routerMain,
    ...routerContent
  ]
})

/*
router.beforeEach((to, from, next) => {
  NProgress.start();
  if (to.matched.some(record => record.meta.requiresAuth)) { // 哪些需要验证
    if (!localStorage.getItem("userInfo")) { // token存在条件
      next('/login')
    } else {
      next()
    }
  } else {
    next()
  }
})

router.afterEach((to) => {
  NProgress.done();
  if (util.isDebug) {
    let projectName = localStorage.getItem('projectName');
    if (projectName) {
      title = projectName;
    }
    //修改每个页面的标题
    document.title = title;
  } else {
    if (to.fullPath == '/' || to.fullPath == '') {
      window.open(util.oldServeUrl + 'index', '_self');
    }
  }
})
*/

export default router
